package cn.nebula.core.base.dao;

import java.util.Collection;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.nebula.core.base.model.ValueObject;

/****************************************************
* 文件名：BaseDAO.java
* 文件描述：DAO基层实体类
* 创建人： isquen, 2011 年6 月10 日
* 版本号：1.0
* 修改记录：
****************************************************/
public class BaseDaoImpl extends HibernateDaoSupport implements BaseDAO {

	private static Log log = LogFactory.getLog(BaseDaoImpl.class);

	private SessionFactory sessionFactory;

	public String voClazzName;


	public void create(Object obj) throws Exception {
		Session session = sessionFactory.getCurrentSession();
		Transaction tx = session.beginTransaction();
		try {
			session.save(obj);
			tx.commit();
			session.flush();
		} catch (Exception e) {
			log.debug("======Catch Exception--->" + e);
		} finally {
			session.close();
		}
	}

	public void update(Object obj) throws Exception {
		// TODO Auto-generated method stub
		
	}

	public void remove(String key) throws Exception {
		// TODO Auto-generated method stub
		
	}

	public void remove(ValueObject obj) throws Exception {
		// TODO Auto-generated method stub
		
	}

	public void remove(String[] keys) throws Exception {
		// TODO Auto-generated method stub
		
	}

	public DataPackage<?> getDatas(String dql) throws Exception {
		// TODO Auto-generated method stub
		
		DataPackage<?> result = new DataPackage();
		try {
			Collection<?> datas = getHibernateTemplate().find(dql);
			result.setDatas(datas);
		} catch (Exception e) {
			log.debug("======Catch Exception  getDatas--->" + e);
		} 
		return result;
	}

	public DataPackage getDatasBySql(String sql) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	public DataPackage getDatas() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	public Object getData(String dql) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	public DataPackage getDatas(String dql, String params) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	public DataPackage getDatas(String dql, int page, int line)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	public int getTotalLines(String dql) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	public ValueObject find(String key) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	public DataPackage findByAny(ValueObject obj) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

}
